<!-- 物资调拨 -->
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号">
              <a-input placeholder="请输入单据编号" v-model="queryParam.purchaseBill"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <select-material-input v-model="queryParam.materialName" placeholder="请选择物料名称" :materialFlag="false" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <select-user-by-dep placeholder="请选择申请人" :multi="false" v-model="queryParam.handlerId" />
            </a-form-item>
          </a-col>
          <!-- <template v-if="toggleSearchStatus"></template> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button
        :loading="exportLoading"
        type="primary"
        icon="download"
        @click="handleExportXls('物资调拨明细' + moment().format('YYYY-MM-DD-HH:mm:ss'))"
        :disabled="isDisabledAuth('erpCannibalizeDetailReport:export')"
      >导出
      </a-button>
      <!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
              <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpOmcProject:import')">导入</a-button>
            </a-upload>-->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">
              <a-menu slot="overlay">
                <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpOmcProject:delete')"><a-icon type="delete"/>删除</a-menu-item>
              </a-menu>
              <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
            </a-dropdown>-->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item, index) in defColumns">
                <template v-if="item.key != 'rowIndex' && item.dataIndex != 'action'">
                  <a-col :span="12" :key="index">
                    <a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox>
                  </a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right; margin-top: -20px;">
          <a-icon type="setting" :style="iconStyle" />
        </a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length
        }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: scrollX }"
        bordered
        :components="draggableComponent"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <template slot="purchaseBill" slot-scope="text, record">
          <a @click="handleDetail(record)">{{ text }}</a>
        </template>
        <template slot="status" slot-scope="status">
          <a-badge :status="status | statusTypeFilter" :text="status | statusFilter" />
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="pcaSlot" slot-scope="text">
          <div>{{ getPcaText(text) }}</div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <!--
                <span slot="action" slot-scope="text, record">
                    <a-button
                        class="ruleButton"
                        :ghost="true"
                        type="primary"
                        icon="edit"
                        @click="handleEdit(record)"
                        :disabled="isDisabledAuth('erpOmcProject:edit')"
                />
                <a-divider type="vertical"/>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                    <a-button
                            class="ruleButton"
                            :ghost="true"
                            type="primary"
                            icon="delete"
                            :disabled="isDisabledAuth('erpOmcProject:delete')"/>
                </a-popconfirm>
                </span>
        -->

      </a-table>
    </div>

    <erp-omc-project-modal ref="modalForm" @ok="modalFormOk"></erp-omc-project-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ErpOmcProjectModal from '@views/erp/omc/project/modules/ErpOmcProjectModal'
import Area from '@/components/_util/Area'
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import SelectTeamInput from '@views/scy/components/SelectTeamInput'
import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
import SelectCustomerInput from '@views/scy/components/SelectCustomerInput'
import BusinessCategoryNameSelect from '@views/erp/components/BusinessCategoryNameSelect'
import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
import SelectMaterialInput from '@/views/scy/components/SelectMaterialInput'
import { getAction } from '@/api/manage'
import { mapGetters } from 'vuex'
import moment from 'moment';
export default {
  name: 'ErpPurchaseCannibalizeDetailAllList',
  mixins: [JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
  components: {
    SelectMaterialInput,
    ErpOmcProjectModal,
    SelectTeamInput,
    SelectUserByDep,
    SelectCustomerInput,
    BusinessCategoryNameSelect,
    SelectCompanyInput
  },
  data() {
    return {
      moment,
      /* 排序参数 */
      isorter: {
        column: '',
        order: ''
      },
      description: '入库明细',
      // 表头
      columns: [],
      // 列设置
      settingColumns: [],
      // 列定义
      defColumns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          // fixed: 'left',
          ellipsis: true,
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'purchaseBill',
          ellipsis: true,
          scopedSlots: { customRender: 'purchaseBill' },
          width: 170
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'handlerId_dictText',
          ellipsis: true,
          width: 80
        },
        {
          title: '申请部门',
          align: 'center',
          dataIndex: 'applicant_dictText',
          ellipsis: true,
          width: 135
        },
        {
          title: '调出团队',
          align: 'center',
          dataIndex: 'exportTeamId_dictText',
          ellipsis: true,
          width: 150
        },
        {
          title: '调出日期',
          align: 'center',
          dataIndex: 'exportTime',
          ellipsis: true,
          width: 135
        },
        {
          title: '调出仓库',
          align: 'center',
          dataIndex: 'exportWarehouse_dictText',
          ellipsis: true,
          width: 150
        },
        {
          title: '调入团队',
          align: 'center',
          dataIndex: 'foldTeamId_dictText',
          ellipsis: true,
          width: 150
        },
        {
          title: '调入日期',
          align: 'center',
          dataIndex: 'foldTime',
          ellipsis: true,
          width: 135
        },
        {
          title: '调入仓库',
          align: 'center',
          dataIndex: 'foldWarehouse_dictText',
          ellipsis: true,
          width: 150
        },
        {
          title: '物料大类',
          align: 'center',
          dataIndex: 'provisionBroad_dictText',
          ellipsis: true,
          width: 100
        },
        {
          title: '物料小类',
          align: 'center',
          dataIndex: 'provisionSmall_dictText',
          ellipsis: true,
          width: 100
        },
        {
          title: '物料编号',
          align: 'center',
          dataIndex: 'materialBillId',
          ellipsis: true,
          width: 135
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName_dictText',
          ellipsis: true,
          width: 150
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'specification',
          ellipsis: true,
          width: 110
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit_dictText',
          ellipsis: true,
          width: 60
        },
        {
          title: '品牌',
          align: 'center',
          dataIndex: 'brand',
          ellipsis: true,
          width: 100
        },
        {
          title: '申请调拨数量',
          align: 'center',
          dataIndex: 'amount',
          ellipsis: true,
          width: 130
        },
        {
          title: '实际调拨出库数量',
          align: 'center',
          dataIndex: 'actualAmount',
          ellipsis: true,
          width: 140
        }
        /*  {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          } */
      ],
      url: {
        list: '/api/erp/purchase/recipients/erpPurchaseCannibalizeDetail/reports',
        delete: '/api/erp/purchase/recipients/erpPurchaseCannibalizeDetail/delete',
        deleteBatch: '/api/erp/purchase/recipients/erpPurchaseCannibalizeDetail/deleteBatch',
        exportXlsUrl: '/api/erp/purchase/recipients/erpPurchaseCannibalizeDetail/export/xls',
        importExcelUrl: '/api/erp/purchase/recipients/erpPurchaseCannibalizeDetail/import/xls',
        queryByStorehouseManager: '/api/erp/purchase/storehouse/erpStorehouseBase/queryByStorehouseManager' // 获取仓库
      },
      dictOptions: {},
      pcaData: '',
      superFieldList: [],
      foldWarehouseList: [] // 仓库名称
    }
  },
  created() {
    this.pcaData = new Area()
    this.getSuperFieldList();
    this.findFoldApplicant() // 根据单位查询仓库
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    ...mapGetters(['userInfo']),
    handleDetail: function (record) {
      // const _path = this.$route.path
      // if (_path.startsWith('/hmhb/') || _path.startsWith('/scy/') || _path.startsWith('/imp/')
      //   || _path.startsWith('/erp/')) {
      //   this.$router.push({
      //     path: `${_path}Detail/${record.id}`
      //   })
      // } else {
      //   this.$refs.modalForm.edit(record);
      //   this.$refs.modalForm.title = '详情';
      //   this.$refs.modalForm.disableSubmit = true;
      // }
      //   console.log(this.$route)
      this.$router.push({
        path: `/erp/purchase/recipients/ErpPurchaseCannibalizeListDetail/${record.billId}`
      })
    },
    getPcaText(code) {
      return this.pcaData.getText(code);
    },
    initDictConfig() {
    },
    findFoldApplicant() {
      const that = this
      getAction(this.url.queryByStorehouseManager, { storehouseManager: this.userInfo().empId }).then((res) => {
        if (res.success) {
          that.foldWarehouseList = []
          res.result.forEach((res) => {
            that.foldWarehouseList.push({ 'id': res.id, 'categoryName': res.storehouseName })
          })
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      );
    },
    storehouseChange(data) {
      if (!data) {
        this.$set(this.queryParam, 'storehouseId', undefined)
      }
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({ type: 'string', value: 'year', text: '归属年度', dictCode: 'yjgsnd' })
      fieldList.push({ type: 'string', value: 'accountAdmin', text: '台账管理员', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectAddress', text: '项目地址', dictCode: '' })
      fieldList.push({ type: 'Text', value: 'outline', text: '项目内容概要', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'prepareProjectId',
        text: '预立项',
        dictCode: 'erp_omc_prepare_project,mc,id'
      })
      fieldList.push({ type: 'string', value: 'projectName', text: '项目名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectNo', text: '项目编号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectType', text: '项目类型', dictCode: 'xmlx_type' })
      fieldList.push({ type: 'string', value: 'ownerUnit', text: '业主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handler', text: '经办人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'handingDepartmernt', text: '经办部门', dictCode: 'departments' })
      fieldList.push({ type: 'string', value: 'teamName', text: '经营团队', dictCode: 'teams' })
      fieldList.push({ type: 'string', value: 'undertaker', text: '承接人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'projectEstablishDate', text: '立项日期' })
      fieldList.push({ type: 'string', value: 'signUnit', text: '签订单位', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'estimatedContractAmount', text: '预计合同额(元)', dictCode: '' })
      fieldList.push({ type: 'string', value: 'estimatedContractcapitalChineseAmount', text: '预计合同额(元)大写', dictCode: '' })
      fieldList.push({
        type: 'string',
        value: 'isEnvironmentalAssessmentProject',
        text: '是否环评项目',
        dictCode: 'YES_OR_NO'
      })
      fieldList.push({ type: 'string', value: 'contacts', text: '联系人', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contactTel', text: '联系方式', dictCode: '' })
      fieldList.push({ type: 'string', value: 'projectSource', text: '项目来源', dictCode: 'xmly_type' })
      fieldList.push({ type: 'string', value: 'isPrepareEstablish', text: '数据来源', dictCode: 'omc_project_type' })
      fieldList.push({ type: 'string', value: 'status', text: '流程状态', dictCode: 'project_status' })
      fieldList.push({ type: 'string', value: 'attachment', text: '相关附件', dictCode: '' })
      fieldList.push({ type: 'string', value: 'isPrepareEstablish', text: '是否预立项', dictCode: 'YES_OR_NO' })
      fieldList.push({ type: 'string', value: 'isBidding', text: '是否招投标', dictCode: 'YES_OR_NO' })
      fieldList.push({ type: 'Text', value: 'establishReason', text: '立项事由及说明', dictCode: '' })
      fieldList.push({ type: 'pca', value: 'areaCode', text: '县区编码' })
      this.superFieldList = fieldList
    },
    businessCategoryHandle(obj) {
      if (obj) {
        this.queryParam.businessCategory = obj.categoryCode;
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
